package crane.bomb;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

/**
 * 
 * @author crane
 *
 */
public class MainMenu extends MainFrame{

    /**
     * Constructor
     *
     */
    public MainMenu(){}
    
    /*
     * mBean
     */
    private MainBean mBean;
    
    /**
     * @param mBean
     */
    void setMainBean(MainBean mBean) {
        this.mBean = mBean;        
    }
    
    /**
     * @return mBean
     */
    MainBean getMainBean() {
        return this.mBean;
    }
    
    /*
     * MenuBar
     */
    private JMenuBar mbar = null;
    
    /**
     * Buile menu bar
     * 
     * @param frame
     * @return JMenuBar
     */
    public JMenuBar buileMenuBar(JFrame frame){

        mbar = new JMenuBar();
        mbar.setAutoscrolls(false);
        mbar.setIgnoreRepaint(true);
        mbar.setOpaque(false);
        
        // File Menu
        JMenu menu = buildFileMenu();
        
        mbar.add(menu);
        
        // Help Menu
        menu = buildHelpMenu();
        mbar.add(menu);
        
        JPanel panel = new JPanel();
        panel.setLayout(new FlowLayout());
        mbar.add(panel);
        
        
        return mbar;
    }
    
    /**
     * Buile File menu
     * 
     * @return JMenu
     */
    private JMenu buildFileMenu(){
        JMenu menu = new JMenu("File");
        JMenuItem  item = new JMenuItem("New...");

        item.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                new BombAction().actStartGame(mBean);
            }
        });
        menu.add(item);
        
        menu.addSeparator();
        item = new JMenuItem("Score");
        item.addActionListener(new ActionListener(){
            BombScoreFrame sf = new BombScoreFrame();
            public void actionPerformed(ActionEvent e) {
                sf.setMainBean(mBean);
                new BombAction().clearFrame(mBean.getFrame());
                sf.initFrame(mBean.getFrame());
            }
        });
        menu.add(item);
        
        menu.addSeparator();
        item = new JMenuItem("Exit");
        item.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        menu.add(item);
        return menu;        
    }
    
    /**
     * Buile Help menu
     * 
     * @return JMenu
     */
    private JMenu buildHelpMenu(){
        JMenu menu = new JMenu("Help");
        JMenuItem  item = new JMenuItem("Welcome");

        item.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                // showDialog("The Fuction has not yet finished");
                new BombAction().showModallog(mBean.getFrame(), "Message", "The Fuction has not yet finished!");
            }
        });
        menu.add(item);
        
        menu.addSeparator();
        item = new JMenuItem("About");
        item.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                // showDialog("The Fuction has not yet finished");
                new BombAction().showModallog(mBean.getFrame(), "Message", "The Fuction has not yet finished!");
            }
        });
        menu.add(item);
        return menu;        
    }

}
